package com.zhouyu.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.zhouyu.controller.MyDeSerialize;
import com.zhouyu.controller.MyEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.PostConstruct;
import java.util.List;

@Component
public class ConverterConfig1 implements WebMvcConfigurer {

	@Autowired
	private ObjectMapper objectMapper;

	@PostConstruct
	public void init() {
		System.out.println("111" + objectMapper);
	}

	@Override
	public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
		SimpleModule simpleModule = new SimpleModule();
		simpleModule.addDeserializer(MyEnum.class,new MyDeSerialize());
		objectMapper.registerModule(simpleModule);
	}


}
